Skip to content

Conversation

@constantinius
Copy link
Contributor

@constantinius constantinius commented Dec 17, 2025

@linear
Copy link

linear bot commented Dec 17, 2025

@constantinius constantinius changed the title test(integrations): add test for message conversion fix(openai): convert input message format Dec 17, 2025
@constantinius constantinius marked this pull request as ready for review January 8, 2026 08:34
@constantinius constantinius requested a review from a team as a code owner January 8, 2026 08:34
@constantinius constantinius changed the title fix(openai): convert input message format fix(integrations): openai/openai-agents: convert input message format Jan 8, 2026
Base automatically changed from constantinius/fix/redact-message-parts-type-blob to master January 13, 2026 09:56
@github-actions
Copy link
Contributor

github-actions bot commented Jan 13, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • feat(ai): add parse_data_uri function to parse a data URI by constantinius in #5311
  • feat(asyncio): Add on-demand way to enable AsyncioIntegration by sentrivana in #5288
  • feat(openai-agents): Inject propagation headers for HostedMCPTool by alexander-alderman-webb in #5297
  • feat: Support array types for logs and metrics attributes by alexander-alderman-webb in #5314

Bug Fixes 🐛

  • fix(ai): redact message parts content of type blob by constantinius in #5243
  • fix(clickhouse): Guard against module shadowing by alexander-alderman-webb in #5250
  • fix(gql): Revert signature change of patched gql.Client.execute by alexander-alderman-webb in #5289
  • fix(grpc): Derive interception state from channel fields by alexander-alderman-webb in #5302
  • fix(integrations): openai/openai-agents: convert input message format by constantinius in #5248
  • fix(litellm): Guard against module shadowing by alexander-alderman-webb in #5249
  • fix(pure-eval): Guard against module shadowing by alexander-alderman-webb in #5252
  • fix(ray): Guard against module shadowing by alexander-alderman-webb in #5254
  • fix(threading): Handle channels shadowing by sentrivana in #5299
  • fix(typer): Guard against module shadowing by alexander-alderman-webb in #5253
  • fix: Stop suppressing exception chains in AI integrations by alexander-alderman-webb in #5309
  • fix: Send client reports for span recorder overflow by sentrivana in #5310

Documentation 📚

  • docs(metrics): Remove experimental notice by alexander-alderman-webb in #5304
  • docs: Update Python versions banner in README by sentrivana in #5287

Internal Changes 🔧

Release

  • ci(release): Bump Craft version to fix issues by BYK in #5305
  • ci(release): Switch from action-prepare-release to Craft by BYK in #5290

Other

  • chore(gen_ai): add auto-enablement for google genai by shellmayr in #5295
  • chore: add unlabeled trigger to changelog-preview by BYK in #5315
  • chore: Add type for metric units by sentrivana in #5312
  • ci: Update tox and handle generic classifiers by sentrivana in #5306

🤖 This preview updates automatically when you update the PR.

Copy link
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me, two things:

  • Can we add a check to the tests that we're not modifying the user's messages? Either as a new test or just adding an assert to the tests added in this PR
  • I assume there is no way to dedupe some of the trimming logic between OpenAI agents and OpenAI because the format is different?

@constantinius
Copy link
Contributor Author

Can we add a check to the tests that we're not modifying the user's messages? Either as a new test or just adding an assert to the tests added in this PR

Done

I assume there is no way to dedupe some of the trimming logic between OpenAI agents and OpenAI because the format is different?

Looking into that. Cursor says no. But I'm not sure tbh

… of full message dicts

- Extract choice.message.content for gen_ai.response.text instead of model_dump()
- Add separate gen_ai.response.tool_calls extraction for Chat Completions API
- Handle audio transcripts in responses
- Extract shared extract_response_output() to ai/utils.py for Responses API output
- Refactor OpenAI and OpenAI Agents integrations to use shared utility
@constantinius
Copy link
Contributor Author

I assume there is no way to dedupe some of the trimming logic between OpenAI agents and OpenAI because the format is different?

I did investigate that. I did eliminate code duplication for output messages, but input messages are actually different

…AI messages

Add transform_content_part() and transform_message_content() functions
to standardize content part handling across all AI integrations.

These functions transform various SDK-specific formats (OpenAI, Anthropic,
Google, LangChain) into a unified format:
- blob: base64-encoded binary data
- uri: URL references (including file URIs)
- file: file ID references

Also adds get_modality_from_mime_type() helper to infer content modality
(image/audio/video/document) from MIME types.
Replace local _convert_message_parts function with the shared
transform_message_content function to deduplicate code across
AI integrations.
return "image" # Default fallback for unknown types


def transform_content_part(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create separate transform_openai_content_part(), transform_anthropic_content_part(), and so on, in addition to the generic function?

From my perspective, the heuristics we have for determining if a content block is openai, or anthropic, or another style, is best-effort and can break when input schemas evolve. Maybe a provider becomes more permissive in what they accept, etc ...

We can reduce the risk of trudging into the wrong code paths in client libraries for openai, anthropic, and so forth, by calling the specific methods like transform_openai_content_part where possible.

And in generic libraries like langchain we accept that the heuristics in the generic transform_content_part() is the best we can do.

Add dedicated transform functions for each AI SDK:
- transform_openai_content_part() for OpenAI/LiteLLM image_url format
- transform_anthropic_content_part() for Anthropic image/document format
- transform_google_content_part() for Google GenAI inline_data/file_data
- transform_generic_content_part() for LangChain-style generic format

Refactor transform_content_part() to be a heuristic dispatcher that
detects the format and delegates to the appropriate specific function.

This allows integrations to use the specific function directly for
better performance and clarity, while maintaining backward compatibility
through the dispatcher for frameworks that can receive any format.

Added 38 new unit tests for the SDK-specific functions.
Replace generic transform_message_content with the OpenAI-specific
transform_openai_content_part function for better performance and
clarity since we know OpenAI always uses the image_url format.
@@ -0,0 +1,3 @@
version = 1
revision = 3
requires-python = ">=3.13"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidentally committed uv.lock with wrong Python version

Low Severity

The newly added uv.lock file at the repository root specifies requires-python = ">=3.13", which conflicts with the project's actual Python support (python_requires=">=3.6" in setup.py). This appears to be a development environment artifact that was unintentionally committed. The minimal 3-line lock file is unusual for a root-level lock and doesn't match the project's configuration.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants